package com.zxj.test.common.api;

import org.springframework.http.HttpStatus;

/**
 * @author zxj
 * @date 2020/7/18
 */
public class Response<T> {

    private Integer status;
    private String errMsg;
    private T data;

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static Response<Void> fail(int status, String msg) {
        Response<Void> response = new Response<>();
        response.setStatus(status);
        response.setErrMsg(msg);
        return response;
    }

    public static <T> Response<T> ok(T date) {
        Response<T> response = new Response<>();
        response.setStatus(HttpStatus.OK.value());
        response.setData(date);
        return response;
    }

    public static Response<Void> ok() {
        return ok(null);
    }
}
